package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.APartner;
import com.ruoyi.lock.service.IAPartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合伙人管理Controller
 *
 * @author ruoyi
 * @date 2024-03-10
 */
@RestController
@RequestMapping("/lock/partner")
public class APartnerController extends BaseController
{
    @Autowired
    private IAPartnerService aPartnerService;

    /**
     * 查询合伙人管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(APartner aPartner)
    {
        startPage();
        List<APartner> list = aPartnerService.selectAPartnerList(aPartner);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('lock:partner:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(APartner aPartner)
    {
        List<APartner> list = aPartnerService.selectAPartnerList1(aPartner);
        return getDataTable(list);
    }

    /**
     * 导出合伙人管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:export')")
    @Log(title = "合伙人管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, APartner aPartner)
    {
        List<APartner> list = aPartnerService.selectAPartnerList(aPartner);
        ExcelUtil<APartner> util = new ExcelUtil<APartner>(APartner.class);
        util.exportExcel(response, list, "合伙人管理数据");
    }

    /**
     * 获取合伙人管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aPartnerService.selectAPartnerById(id));
    }

    /**
     * 新增合伙人管理
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:add')")
    @Log(title = "合伙人管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody APartner aPartner)
    {
        return toAjax(aPartnerService.insertAPartner(aPartner));
    }

    /**
     * 修改合伙人管理
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:edit')")
    @Log(title = "合伙人管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody APartner aPartner)
    {
        return toAjax(aPartnerService.updateAPartner(aPartner));
    }

    /**
     * 删除合伙人管理
     */
    @PreAuthorize("@ss.hasPermi('lock:partner:remove')")
    @Log(title = "合伙人管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aPartnerService.deleteAPartnerByIds(ids));
    }

    /**
     * 获取合伙人总数
     * @return
     */
    @GetMapping("/partnerTotal")
    public AjaxResult getPartnerTotal(){
        return success(aPartnerService.getPartnerTotal());
    }

    /**
     * 查询投资人、代理商数量
     */
    @GetMapping("/selectPartnerCount")
    public AjaxResult selectPartnerCount(){
        return success(aPartnerService.selectPartnerCount());
    }
}